package cn.tpshion.vm.handler.task.support;

import cn.tpshion.vm.common.exception.BizException;
import cn.tpshion.vm.common.utils.AssertUtil;
import cn.tpshion.vm.domain.support.NodeContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

@Component
public class NodeFactory {

    @Autowired
    private List<NodeHandler> handlerList;

    public NodeHandler getHandler(NodeContext context) {
        AssertUtil.isEmpty(handlerList, "节点处理器为空");
        return handlerList.stream().filter(
                i -> i.support(context.getType())
        ).findFirst().orElseThrow(() -> new BizException("未找到可用节点处理器"));
    }
}
